package com.example.patch.download;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.List;

public class DownLoaderTest {

    public static void main(String[] args) throws IOException {
        List<String> urls = FileUtils.readLines(new File("url.txt"), "utf-8");
        for (String url : urls) {
            if (StringUtils.isBlank(url)) {
                continue;
            }
            String fileName = URLDecoder.decode(url, "UTF-8").substring(URLDecoder.decode(url, "UTF-8").lastIndexOf('/') + 1);
            File downLoadFile = new File("/视频/深入剖析Kubernetes/" + fileName);
            System.err.println("start downLoad file " + fileName);
            FileUtils.copyURLToFile(new URL(url), downLoadFile);
            System.err.println("downLoad file " + fileName + " completed, save path: " + downLoadFile.getAbsolutePath());
        }
    }
}
